#include "npapi.h"
#include "npfunctions.h"

#include "plugin.h"
#include "common.h"

NPNetscapeFuncs* browserFuncs = 0;

BOOL WINAPI DllMain(
  HINSTANCE hinstDLL,
  DWORD fdwReason,
  LPVOID lpvReserved)
{
	TRACE("DllMain(%p, %u)", hinstDLL, fdwReason);
	BOOL res;
	switch(fdwReason)
	{
	case DLL_PROCESS_ATTACH:
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		res = TRUE;
		break;
	default:
		res = FALSE;
	}
	return res;
}

extern "C" NPError OSCALL NP_Initialize(NPNetscapeFuncs* bFuncs)
{
	TRACE("NP_Initialize");
	if(bFuncs == NULL || bFuncs->size <= ((unsigned int)&((NPNetscapeFuncs*)0)->setexception))
		return NPERR_INVALID_FUNCTABLE_ERROR;
	if(HIBYTE(bFuncs->version) > NP_VERSION_MAJOR)
		return NPERR_INCOMPATIBLE_VERSION_ERROR;

	browserFuncs = bFuncs;

	return NPERR_NO_ERROR;
}

NPError OSCALL NP_Shutdown()
{
	TRACE("NP_Shutdown");
	return NPERR_NO_ERROR;
}

NPError OSCALL NP_GetEntryPoints(NPPluginFuncs* pFuncs)
{
	TRACE("NP_GetEntryPoints");
	if(pFuncs == NULL)
		return NPERR_INVALID_FUNCTABLE_ERROR;

	pFuncs->newp = New;
	pFuncs->destroy = Destroy;
	pFuncs->setwindow = SetWindow;
	pFuncs->newstream = NewStream;
	pFuncs->destroystream = DestroyStream;
	pFuncs->asfile = StreamAsFile;
	pFuncs->writeready = WriteReady;
	pFuncs->write = Write;
	pFuncs->print = Print;
	pFuncs->event = HandleEvent;
	pFuncs->urlnotify = URLNotify;
	pFuncs->getvalue = GetValue;
	pFuncs->setvalue = SetValue;

	return NPERR_NO_ERROR;
}
